﻿using DevComponents.DotNetBar;
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace chatSDKApp.Forms
{
    public partial class FrmAlertCustom : Balloon
    {
        #region 私有方法

        private readonly bool _isAlarm = false;
        private string _eventName = null;
        #endregion

        #region 自定义事件
        /// <summary>
        /// 点击查看按钮时触发
        /// </summary>
        public event EventHandler ClickView;

        private void OnClickView()
        {
            ClickView?.Invoke(this.biView, new EventArgs());
        }

        #endregion

        #region 公共属性

        private string _title;
        /// <summary>
        /// 设置或获取提示的标题
        /// </summary>
        private string Title
        {
            set
            {
                _title = value;
                this.labTitle.Text = value;
            }
            get => _title;
        }

        private string _content;
        /// <summary>
        /// 设置或获取提示的内容
        /// </summary>
        public string Content
        {
            set
            {
                _content = value;
                this.labContent.Text = value;
            }
            get => _content;
        }

        private int Zindex { get; set; }

        /// <summary>
        /// 自己确认的不关闭窗口
        /// </summary>
        public bool MeCommit { get; private set; }
        #endregion

        #region 构造方法
        /// <summary>
        /// 自定义提示窗口
        /// </summary>
        private FrmAlertCustom()
        {
            InitializeComponent();
            RegiterControlEvent();
            MeCommit = false;
        }

        /// <summary>
        /// 自定义提示窗口
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="content">内容</param>
        public FrmAlertCustom(string title, string content) : this()
        {
            this.Title = title;
            this.Content = content;
        } 
        public FrmAlertCustom(string title, string content, bool smart) : this()
        {
            this.Title = title;
            this.Content = content;
            biView.Visible = biView.Enabled = true;
        }

        #endregion

        #region 控件注册事件      

        private void RegiterControlEvent()
        {
            this.biView.Click += BiViewOnClick;
            this.labContent.Click += BiViewOnClick;
        }

        private void BiViewOnClick(object sender, EventArgs eventArgs)
        {
            this.OnClickView();
            this.Close();
        }

        #endregion

        #region 公共方法
        /// <summary>
        /// 显示提示窗口
        /// </summary>
        public void ShowAlert()
        {
            Rectangle r = Screen.GetWorkingArea(this);
            if (_isAlarm)
                this.Location = new Point(r.Right - this.Width * 3 - 6, r.Bottom - this.Height);
            else
                this.Location = new Point(r.Right - this.Width - 3, r.Bottom - this.Height);
            this.AutoClose = true;
            this.TopMost = false;
            this.AutoCloseTimeOut = 30;
            this.AlertAnimation = eAlertAnimation.BottomToTop;
            this.AlertAnimationDuration = 300;
            this.Zindex = 10;
            this.Show(false);


        }
        /// <summary>
        /// 其它系统推送过来的信息文本
        /// </summary>
        public void ShowPushMessage()
        {
            if (!biView.Visible)
            {
                this.biView.Click -= BiViewOnClick;
                this.labContent.Click -= BiViewOnClick;
            }

            Rectangle r = Screen.GetWorkingArea(this);
            this.Location = new Point(r.Right - this.Width * 2 - 6, r.Bottom - this.Height);
            this.AutoClose = true;
            this.AutoCloseTimeOut = 24 * 60 * 60;
            this.AlertAnimation = eAlertAnimation.BottomToTop;
            this.AlertAnimationDuration = 300;
            TopMost = true;
            this.Show(false);
        }


        #endregion

        #region 移动
        private Point _mouseOffset;

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) //按下的是鼠标左键            
            {
                _mouseOffset = e.Location;
            }
        }

        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Location = new Point(Location.X + e.X - _mouseOffset.X, Location.Y + e.Y - _mouseOffset.Y);
            }
        }
        #endregion
    }
}
